home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
cdity
/
ModeProSrc.lha
/
Prefs
/
MPPLoadPalette.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-08
|
3KB
|
115 lines
#include "MPP.h"
#include <datatypes/pictureclass.h>
extern UBYTE filename[513];
extern struct FileRequester *PalFileReq;
BOOL SelectPaletteFile(UBYTE *title,UBYTE save,struct Window *Parent);
/*
BOOL LoadPalette(struct DefaultNode *DN)
{
if(SelectPalFile("Open Palette",0))
{
return(ReadCMAP(DN,filename));
}
return(0);
}
*/
BOOL ReadCMAP(STRPTR Filename, struct RGB *CReg, ULONG Colors)
{
struct IFFHandle *iff;
struct StoredProperty *sp;
// struct BitMapHeader *bmhd;
struct ColorRegister *cmap;
LONG l;
LONG error=0,rv;
rv=0;
if(iff=AllocIFF())
{
if(iff->iff_Stream = Open (Filename,MODE_OLDFILE))
{
InitIFFasDOS(iff);
if(!(error=OpenIFF(iff,IFFF_READ)) )
{
if (!(error=PropChunk(iff,ID_ILBM,ID_CMAP)))
{
if(!(error=StopOnExit(iff,ID_ILBM,ID_FORM)))
{
if((error=ParseIFF(iff,IFFPARSE_SCAN))>-3)
{
if(sp=FindProp(iff,ID_ILBM,ID_CMAP))
{
cmap =(struct ColorRegister *)sp->sp_Data;
Colors =min(sp->sp_Size/3,Colors);
for(l=0;l<Colors;l++)
{
CReg[l].Red =cmap[l].red * 0x01010101;
CReg[l].Green=cmap[l].green * 0x01010101;
CReg[l].Blue =cmap[l].blue * 0x01010101;
}
rv=1;
}
}/* end ParseIFF if */
}
} /* End Prop MPPR */
CloseIFF(iff);
}
Close(iff->iff_Stream);
}
FreeIFF(iff);
}
return(rv);
}
BOOL SaveCMAP(STRPTR Filename, struct RGB *CReg, ULONG Colors)
{
struct ColorRegister cmap[256];
struct IFFHandle *iff;
ULONG len,l;
LONG error;
UWORD font;
ULONG flags;
struct DefaultNode *n;
SetIoErr(0);
error=1;
if(iff=AllocIFF())
{
if(iff->iff_Stream = Open (Filename,MODE_NEWFILE))
{
InitIFFasDOS(iff);
if( !(error=OpenIFF(iff,IFFF_WRITE)) )
{
if(!(error=PushChunk(iff,ID_ILBM,ID_FORM, IFFSIZE_UNKNOWN)))
{
if(!(error=PushChunk(iff,ID_ILBM,ID_CMAP, Colors * sizeof(cmap[0]))))
{
for(l=0;l<Colors;l++)
{
cmap[l].red =CReg[l].Red>>24;
cmap[l].green =CReg[l].Green>>24;
cmap[l].blue =CReg[l].Blue>>24;
}
error=WriteChunkBytes(iff,cmap,Colors * sizeof(cmap[0]));
}
error|=PopChunk(iff);
}
CloseIFF(iff);
}
Close(iff->iff_Stream);
}
FreeIFF(iff);
}
if(error<0)
return(FALSE);
else
return(TRUE);
}